import { Gain } from "../../../info/GameEnum";
import { DecisionNode } from "../DecisionTree";

/**
 * 升级主基地
 */
export default class DecisionMainHomeLevelUp extends DecisionNode {

    evaluate(): number {
        if (!this.environment.player.checkGainCondition(Gain.升级主基地).every(item => item))
            return 0;

        //有多少决策是因为基地等级不够
        let count = 0,
            size = this.environment.gainFeasibility.size + this.environment.facilityFeasibility.size;
        let addFunc = (v: boolean[]) => {
            v[2] && count++;
        }
        this.environment.gainFeasibility.forEach(addFunc);
        this.environment.facilityFeasibility.forEach(addFunc);
        return Math.ceil(20 + count / size * 100);
    }

    execute(): number {
        this.environment.player.MainHomeLevelUp();
        return 0;
    }
}